const mongoose = require('mongoose')

const Schema = mongoose.Schema
// 注意保留8位
const schema = new Schema({
  // 名称
  name: String,
  // 编码
  code: String,
  // 频率H：小时, D：日
  frequency: String,
  // 状态
  // 0禁用,1开启
  status: {
    type: Number,
    default: 0
  },
  xh_status: {
    type: Number,
    default: 0
  },
  hy_status: {
    type: Number,
    default: 0
  },
  buy_status: {
    type: Number,
    default: 0
  },
  sell_status: {
    type: Number,
    default: 0
  },
  // 分配的usdt数量
  usdt: {
    type: Number,
    default: 0
  },
  // 当前所剩的usdt数量
  now_usdt: {
    type: Number,
    default: 0
  },
  // 累计
  total_income_usdt: {
    type: Number,
    default: 0
  },
  // 累计手续费
  total_charge_usdt: {
    type: Number,
    default: 0
  },
  buy_times: {
    type: Number,
    default: 0
  },
  last_buy_times: {
    type: Number,
    default: 0
  },
  sell_times: {
    type: Number,
    default: 0
  },
  last_sell_times: {
    type: Number,
    default: 0
  },
  min_qty: {
    type: Number,
    default: 0
  },
  max_qty: {
    type: Number,
    default: 0
  },
  step_size: {
    type: Number,
    default: 0
  },
  min_notional: {
    type: Number,
    default: 0
  },
  tick_size: {
    type: Number,
    default: 0
  },
  f_min_qty: {
    type: Number,
    default: 0
  },
  f_max_qty: {
    type: Number,
    default: 0
  },
  f_step_size: {
    type: Number,
    default: 0
  },
  f_min_notional: {
    type: Number,
    default: 0
  },
  f_tick_size: {
    type: Number,
    default: 0
  },
  // 占比
  proportion: {
    type: Number,
    default: 0
  },
  condition_buy_status: {
    type: Number,
    default: 0
  },
  condition_sell_status: {
    type: Number,
    default: 0
  },
  // 分数
  condition_buy_number: {
    type: Number,
    default: 0
  },
  condition_sell_number: {
    type: Number,
    default: 0
  },
  bpc: {
    type: Number,
    default: 0
  },
  // 使用策略
  strategy: {
    type: String,
    default: ''
  },
  strategy_result: {
    type: String,
    default: ''
  },
  // 小时的ema5-ema10
  hourEma510: {
    type: Number,
    default: 0
  },
  dayEmaInfo: {
    type: Object,
    default: {}
  },
  hourEmaInfo: {
    type: Object,
    default: {}
  },
  hour4EmaInfo: {
    type: Object,
    default: {}
  },
  weekEmaInfo: {
    type: Object,
    default: {}
  },
  monthEmaInfo: {
    type: Object,
    default: {}
  },
  minute15EmaInfo: {
    type: Object,
    default: {}
  },
  countResultInfo: {
    type: Object,
    default: {}
  },
  sell_order_id: {
    type: String,
    default: ''
  },
  buy_order_id: {
    type: String,
    default: ''
  },
  market_buy_order_id: {
    type: String,
    default: ''
  },
  market_sell_order_id: {
    type: String,
    default: ''
  },
  stop_profit_order_id: {
    type: String,
    default: ''
  },
  // 交易方向，多，空
  direction: {
    type: String,
    default: ''
  },
  buy_sell_reason: {
    type: String,
    default: ''
  },
  // 持仓数量，作对比，来判断止盈单是否触发了
  now_position_usdt: {
    type: Number,
    default: 0
  },
  now_position_amt: {
    type: Number,
    default: 0
  },
  // 仓位价格
  now_position_cost_price: {
    type: Number,
    default: 0
  },
  // 止盈价格
  stop_profit_price: {
    type: Number,
    default: 0
  },
  stop_profit_rate: {
    type: Number,
    default: 0
  },
  // 15m:0,1h:10,4h:20,id:30
  direction_level: {
    type: Number,
    default: 0
  },
  leverage: {
    type: Number,
    default: 20
  },
  // 是否在下个K平仓，0:否，1:是
  ping_next_k: {
    type: Number,
    default: 0
  },
  // 是否在下个K平仓，0:否，1:是
  ping_next_1hk: {
    type: Number,
    default: 0
  },
  // 手动还是自动，0:自动，1:手动
  manual: {
    type: Number,
    default: 0
  },
  keep_days: {
    type: Number,
    default: 0
  },
  add_times: {
    type: Number,
    default: 0
  },
  max_all15m_times: {
    type: Number,
    default: 0
  },
  max_income_rate: {
    type: Number,
    default: 0
  },
  price_change_rank: {
    type: Number,
    default: 0
  },
  // 当前持仓的记录
  position_record: {
    type: Array,
    default: []
  },
  error_track: {
    type: Array,
    default: []
  },
  // 废弃
  track_list: {
    type: Array,
    default: []
  },
  reason_list: {
    type: Array,
    default: []
  },
  // 买卖分析结果
  buy_sell_analysis_result: {
    type: Object,
    default: {}
  },
  // 24小时
  price_change_percent: {
    type: Number,
    default: 0
  },
  // 成交
  quote_volume: {
    type: Number,
    default: 0
  },
  // 0.1%波动下的挂单数
  register_usdt_010: {
    type: Number,
    default: 0
  },
  // 0.15%波动下的挂单数
  register_usdt_015: {
    type: Number,
    default: 0
  },
  // 0.2%波动下的挂单数
  register_usdt_020: {
    type: Number,
    default: 0
  },
  // 黑名单,0不是,1是
  blacklist: {
    type: Number,
    default: 0
  },
  // operation_time: Date,
  create_at: {
    type: Date,
    default: Date.now
  }
})

schema.index({ code: 1 }, { unique: true })
schema.index({ create_at: -1 })

module.exports = mongoose.model('BtbIndex', schema)
